//
//  Person.m
//  HomeWork-weekend
//
//  Created by 岁变 on 16/7/8.
//  Copyright © 2016年 岁变. All rights reserved.
//

#import "Person.h"

@implementation Person

- (instancetype)initWithName:(NSString *)name age:(NSInteger)age {
    self = [super init];
    if (self) {
        _name = name;
        _age = age;
    }
    return self;
}

+ (instancetype)personWithName:(NSString *)naem age:(NSInteger)age {
    Person *per = [[Person alloc] initWithName:naem age:age];
    return per;
}

- (NSString *)description {
    return [NSString stringWithFormat:@"name %@  age %ld", self.name, self.age];
}

- (NSComparisonResult)asSortedByName:(Person *)per {
    return [self.name compare:per.name];
}

- (NSComparisonResult)asSortedByAge:(Person *)per {
    if (self.age > per.age) {
        return NSOrderedDescending;
    } else if (self.age < per.age) {
        return NSOrderedAscending;
    } else {
        return NSOrderedSame;
    }
}

@end
